#!/usr/bin/perl
use ExtUtils::testlib;
use Wiimote;
print qq!
         test.pl - libwiimote perl module test application

         A    - hold to Enable accelerometer
         1    - hold to Enable rumble
         Home - Exit

        Press buttons 1 and 2 on the wiimote now to connect.
!;

print "Connect " . Wiimote::wiimote_connect('00:19:1D:75:CC:30');
print "\n-------------------\n";

print "Is open: " . Wiimote::is_open();
print "\n-------------------\n";
while ( Wiimote::is_open() ) {
    Wiimote::wiimote_update();
    Wiimote::set_wiimote_rumble(0);
    if (Wiimote::get_wiimote_keys_1) {
        Wiimote::set_wiimote_rumble(1);
    }
    else {
        Wiimote::set_wiimote_rumble(0);
    }
    if (Wiimote::get_wiimote_keys_a) {
        Wiimote::activate_wiimote_accelerometer();
    }
    else {
        Wiimote::deactivate_wiimote_accelerometer();
    }

    print "Wiimote Key bits: " . Wiimote::get_wiimote_keys_bits();
    print "\n";

    print "Wiimote X axis : " . Wiimote::get_wiimote_axis_x();
    print " y axis : " . Wiimote::get_wiimote_axis_y();
    print " z axis : " . Wiimote::get_wiimote_axis_z();
    print "\n";

    print "Wiimote X tilt : " . Wiimote::get_wiimote_tilt_x();
    print " y tilt : " . Wiimote::get_wiimote_tilt_y();
    print " z tilt : " . Wiimote::get_wiimote_tilt_z();
    print "\n";

    print "nunchuck X : " . Wiimote::get_wiimote_ext_nunchuk_axis_x();
    print " Y : " . Wiimote::get_wiimote_ext_nunchuk_axis_y();
    print " Z : " . Wiimote::get_wiimote_ext_nunchuk_axis_z();
    print " Key c : " . Wiimote::get_wiimote_ext_nunchuk_keys_c();
    print " Key z : " . Wiimote::get_wiimote_ext_nunchuk_keys_z();
    print " Joystick x : " . Wiimote::get_wiimote_ext_nunchuk_joyx();
    print " y : " . Wiimote::get_wiimote_ext_nunchuk_joyy();
    print "\n-------------------\n";

    if (Wiimote::get_wiimote_keys_home) {
       Wiimote::wiimote_disconnect();
    }
    if (Wiimote::get_wiimote_keys_up) {
      print "\n UP \n";
    }
    if (Wiimote::get_wiimote_keys_down) {
      print "\n DOWN \n";
    }
    if (Wiimote::get_wiimote_keys_left) {
      print "\n LEFT \n";
    }
    if (Wiimote::get_wiimote_keys_right) {
      print "\n RIGHT \n";
    }
    if (Wiimote::get_wiimote_keys_a) {
      print "\n A KEY \n";
    }
    if (Wiimote::get_wiimote_keys_b) {
      print "\n B KEY \n";
    }
    if (Wiimote::get_wiimote_keys_1) {
      print "\n 1 KEY \n";
    }
    if (Wiimote::get_wiimote_keys_2) {
      print "\n 2 KEY \n";
    }
    if (Wiimote::get_wiimote_keys_minus) {
      print "\n MINUS KEY \n";
    }
    if (Wiimote::get_wiimote_keys_plus) {
      print "\n PLUS KEY \n";
    }

}

